package com.mastercard.labs

class Card {

	static auditable = true
	
    static constraints = {
		//used in prod
		//number creditCard: true, unique: true
		//used in sit
		number nullable: false, blank:false, matches: '(\\d){16}', unique: true
		expiry nullable: false, blank:false,  matches: '^([1][012]|[0][1-9])/(\\d){2}$'
		cvv2 nullable: false, blank:false, matches: '^(\\d){3}$'
		//holder size: 1..15
		creditLimit nullable: true, range: 1..100000000
    }
	
	String number
	String expiry
	String cvv2
	String holderName
	Bank bank
	String brand
	String holder
	Integer creditLimit
	boolean deleted
	
	String maskNumber() {
		return number.substring(12)
	}
	
	String getMaskNumber() {
		if(number == null||number.isEmpty()||number.length()!=16) {
			return null
		}
		return "xxxxxxxxxxxx"+number.substring(12)
	}
	
	String toString(){
		return number
	}
}
